<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>管理界面</title>
    <style>
        /* 全局样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            background-color: #f4f4f4;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        /* 头部样式 */
        header {
            background-color: #333;
            color: #fff;
            padding: 1rem;
            margin-bottom: 2rem;
            border-radius: 8px;
        }

        header h1 {
            margin-bottom: 1rem;
        }

        nav ul {
            list-style: none;
            display: flex;
            gap: 1rem;
            flex-wrap: wrap;
        }

        nav a {
            color: #fff;
            text-decoration: none;
            padding: 0.5rem 1rem;
            border-radius: 4px;
            transition: background-color 0.3s;
        }

        nav a:hover {
            background-color: #555;
        }

        /* 登录页面样式 */
        .login-container {
            max-width: 400px;
            margin: 100px auto;
            padding: 2rem;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .form-group {
            margin-bottom: 1rem;
        }

        .form-group label {
            display: block;
            margin-bottom: 0.5rem;
        }

        .form-group input {
            width: 100%;
            padding: 0.5rem;
            border: 1px solid #ddd;
            border-radius: 4px;
        }

        .form-group button {
            width: 100%;
            padding: 0.75rem;
            background-color: #333;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        .form-group button:hover {
            background-color: #555;
        }

        /* 仪表盘样式 */
        .dashboard {
            padding: 2rem;
        }

        .stats {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 2rem;
            margin-top: 2rem;
        }

        .stat-card {
            background-color: #fff;
            padding: 1.5rem;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .stat-card h3 {
            margin-bottom: 1rem;
            color: #333;
        }

        .btn {
            display: inline-block;
            padding: 0.5rem 1rem;
            background-color: #333;
            color: #fff;
            text-decoration: none;
            border-radius: 4px;
            margin-top: 1rem;
        }

        .btn:hover {
            background-color: #555;
        }

        /* 表格样式 */
        table {
            width: 100%;
            border-collapse: collapse;
            margin: 1rem 0;
            background-color: #fff;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        }

        th, td {
            padding: 0.75rem;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }

        th {
            background-color: #f8f9fa;
            font-weight: 600;
        }

        tr:hover {
            background-color: #f5f5f5;
        }

        /* 表单样式 */
        form {
            background-color: #fff;
            padding: 2rem;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            max-width: 800px;
            margin: 0 auto;
        }

        .form-row {
            margin-bottom: 1rem;
        }

        .form-row label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: 600;
        }

        .form-row input[type="text"],
        .form-row input[type="number"],
        .form-row select,
        .form-row textarea {
            width: 100%;
            padding: 0.5rem;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 1rem;
        }

        .form-row textarea {
            min-height: 100px;
            resize: vertical;
        }

        .form-actions {
            margin-top: 2rem;
            display: flex;
            gap: 1rem;
            justify-content: flex-end;
        }

        .btn-primary {
            background-color: #007bff;
        }

        .btn-primary:hover {
            background-color: #0056b3;
        }

        .btn-danger {
            background-color: #dc3545;
        }

        .btn-danger:hover {
            background-color: #c82333;
        }

        /* 提示消息样式 */
        .alert {
            padding: 1rem;
            margin-bottom: 1rem;
            border-radius: 4px;
        }

        .alert-success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        .alert-danger {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }

        main {
            background-color: #fff;
            padding: 2rem;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        @media (max-width: 768px) {
            nav ul {
                flex-direction: column;
            }

            nav a {
                display: block;
                text-align: center;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>管理界面</h1>
            <nav>
                <ul>
                    <li><a href="/db/index">首页</a></li>
                    <li><a href="/db/routes">路由配置</a></li>
                    <li><a href="/db/routes/changes">路由变更</a></li>
                    <li><a href="/db/routes/versions">版本信息</a></li>
                    <li><a href="/db/modules">模块管理</a></li>
                    <li><a href="/db/commands">子模块管理</a></li>
                    <li><a href="/logout">退出</a></li>
                </ul>
            </nav>
        </header>
        <main>
            {{content}}
        </main>
    </div>
    <script>
        // 这里可以添加需要的JavaScript代码
        function deleteRoute(id) {
            if (confirm('确定要删除这条路由吗？')) {
                fetch(`/api/routes/${id}`, {
                    method: 'DELETE'
                }).then(response => response.json())
                .then(data => {
                    if (data.status === 'success') {
                        showSuccess(data.message || '删除成功');
                        setTimeout(() => window.location.reload(), 1500);
                    } else {
                        showError(data.message || '删除失败');
                    }
                })
                .catch(error => {
                    console.error('删除路由失败:', error);
                    showError('删除失败，请检查网络或联系管理员');
                });
            }
        }

        function deleteMod(id) {
            if (confirm('确定要删除这个模块吗？')) {
                fetch(`/api/modules/${id}`, {
                    method: 'DELETE'
                }).then(response => response.json())
                .then(data => {
                    if (data.status === 'success') {
                        showSuccess('删除成功');
                        setTimeout(() => window.location.reload(), 1500);
                    } else {
                        showError(data.message || '删除失败');
                    }
                })
                .catch(error => {
                    console.error('删除模块失败:', error);
                    showError('删除失败');
                });
            }
        }

        function deleteCmd(id) {
            if (confirm('确定要删除这个命令吗？')) {
                fetch(`/api/commands/${id}`, {
                    method: 'DELETE'
                }).then(response => response.json())
                .then(data => {
                    if (data.status === 'success') {
                        showSuccess(data.message || '删除成功');
                        setTimeout(() => window.location.reload(), 1500);
                    } else {
                        showError(data.message || '删除失败');
                    }
                })
                .catch(error => {
                    console.error('删除命令失败:', error);
                    showError('删除失败，请检查网络或联系管理员');
                });
            }
        }

        function showSuccess(message) {
            const alert = document.createElement('div');
            alert.className = 'alert alert-success';
            alert.textContent = message;
            document.querySelector('.container').insertBefore(alert, document.querySelector('main'));
            setTimeout(() => alert.remove(), 3000);
        }

        function showError(message) {
            const alert = document.createElement('div');
            alert.className = 'alert alert-danger';
            alert.textContent = message;
            document.querySelector('.container').insertBefore(alert, document.querySelector('main'));
            setTimeout(() => alert.remove(), 3000);
        }
    </script>
</body>
</html>
